תוכנה 1. תרגול מספר 11: Static vs. Dynamic Binding מחלקות מקוננות Nested Classes בית הספר למדעי המחשב אוניברסיטת תל אביב

Size: px
Start display at page:

Download "תוכנה 1. תרגול מספר 11: Static vs. Dynamic Binding מחלקות מקוננות Nested Classes בית הספר למדעי המחשב אוניברסיטת תל אביב"

Transcription

1 תוכנה 1 תרגול מספר 11: Static vs. Dynamic Binding מחלקות מקוננות Nested Classes בית הספר למדעי המחשב אוניברסיטת תל אביב 1

2 2 STATIC VS. DYNAMIC BINDING

3 3 Static versus Dynamic Binding public class Account { public String getname(){...; public void deposit(int amount) {...; public class SavingsAccount extends Account { public void deposit(int amount) {...; Account obj = new Account(); obj.getname(); obj.deposit( ); Account obj = new SavingsAccount(); obj.getname(); obj.deposit( ); Which version is called?

4 4 Binding in Java The process by which references are bound to specific classes. Used to resolve which methods and variables are used at run time. Static Binding (Early Binding) The compiler can resolve the binding at the compile time. Dynamic Binding (Late Binding) The compiler is not able to resolve the call and the binding is done at runtime only. Dynamic dispatch

5 5 Static binding (or early binding) Static binding: bind at compilation time Performed if the compiler can resolve the binding at compile time Applied for Static methods Private methods Final methods Fields

6 6 Static binding example Static methods public class A { public static void m() { System.out.println ( A ); public class B extends A { public static void m() { System.out.println ( B ); public class StaticBindingTest { public static void main(string args[]) { A.m(); B.m(); Output: A B A A A a = new A(); A b = new B(); a.m(); b.m();

7 7 Static binding example - Fields public class A { public String somestring = member of A ; public class B extends A { public String somestring = member of B ; public class StaticBindingTest { public static void main(string args[]) { A a = new A(); A b = new B(); B c = new B(); System.out.println( a.somestring ); System.out.println( b.somestring ); System.out.println( c.somestring ); Output: member of A member of A member of B

8 8 When to bind? void func (Account obj) { obj.deposit(); What should the compiler do here? The compiler doesn t know which concrete object type is referenced by obj the method to be called can only be known at run time (because of polymorphism and method overriding) Run-time binding

9 9 Dynamic Binding public class DynamicBindingTest { public static void main(string args[]) { Vehicle vehicle = new Car(); vehicle.start(); class Vehicle { public void start() { //The reference type is Vehicle but run-time object will be Car //Car's start called because start() is overridden method System.out.println("Inside start method of Vehicle"); class Car extends Vehicle public void start() { System.out.println("Inside start method of Car"); Output: Inside start method of Car

10 10 NESTED CLASSES מחלקות מקוננות

11 11 מחלקה מקוננת Class) )Nested מחלקה מקוננת היא מחלקה המוגדרת בתוך מחלקה אחרת. סוגים: סטטית member( )static לא סטטית member( )non-static אנונימית )anonymous( לא נראה היום מקומית )local( מחלקות פנימיות )inner( class Outer { static class NestedButNotInner {... class Inner {...

12 12 בשביל מה זה טוב? קיבוץ לוגי אם משתמשים בטיפוס מסוים רק בהקשר של טיפוס אחר, את הטיפוס כדי לשמר את הקשר הלוגי. הכמסה מוגברת נטמיע על ידי הטמעת טיפוס אחד באחר אנו חושפים את המידע הפרטי רק לטיפוס המוטמע ולא לכולם. קריאות מיקום הגדרת טיפוס בסמוך למקום השימוש בו.

13 13 מחלקות מקוננות - תכונות משותפות למחלקה מקוננת יש גישה לשדות הפרטיים של המחלקה העוטפת ולהיפך הנראות של המחלקה היא עבור אלו הן מחלקות )כמעט( יכולות להיות אבסטרקטיות, אחרות וכדומה "צד שלישי" רגילות לכל דבר ועניין לממש מנשקים, לרשת ממחלקות

14 14 Static Member Class מחלקה רגילה ש"במקרה" מוגדרת בתוך מחלקה אחרת החוקים החלים על איברים סטטיים אחרים חלים גם על מחלקות סטטיות גישה לשדות / פונקציות סטטיים בלבד גישה לאיברים לא סטטיים רק בעזרת הפניה לאובייקט גישה לטיפוס בעזרת שם המחלקה העוטפת OuterClass.StaticNestedClass יצירת אובייקט OuterClass.StaticNestedClass nested = new OuterClass.StaticNestedClass();

15 15 AbstractMap public abstract class AbstractMap<K,V> implements Map<K,V> { public static class SimpleEntry<K,V> implements Entry<K,V>, java.io.serializable { private final K key; private V value;......

16 16 Non-static Member Class כל מופע של המחלקה הפנימית משויך למופע של המחלקה החיצונית מופע של המחלקה הפנימית מופע של המחלקה החיצונית השיוך מבוצע בזמן יצירת האובייקט ואינו ניתן לשינוי באובייקט הפנימי קיימת הפניה לאובייקט החיצוני )qualified this(

17 17 House Example public class House { private String address; public class Room { // implicit reference to a House private double width; private double height; public String tostring(){ return "Room inside: " + address; גישה למשתנה פרטי לא סטטי

18 18 Inner Classes public class House { private String address; Height of House private double height; public class Room { // implicit reference to a House private double height; Height of Room public String tostring(){ Same as this.height return "Room height: " + height + " House height: " + House.this.height;

19 19 AbstractList public abstract class AbstractList<E> extends AbstractCollection<E> implements List<E> { public Iterator<E> iterator() { return new Itr(); private class Itr implements Iterator<E> {... private class ListItr extends Itr implements ListIterator<E> {...

20 20 יצירת מופעים כאשר המחלקה העוטפת יוצרת מופע של עצם מטיפוס המחלקה הפנימית אזי העצם נוצר בהקשר של העצם היוצר כאשר עצם מטיפוס המחלקה הפנימית נוצר מחוץ למחלקה העוטפת, יש צורך בתחביר מיוחד outerobject.new InnerClassConstructor( ) 20

21 21 מחלקות אנונימיות מחלקה ללא שם הגדרה ויצירת מופע בנקודת השימוש מגבלות: חייבת לרשת מטיפוס קיים )מנשק או מחלקה( לא ניתן להגדיר איברים סטטיים, לא ניתן להשתמש בהקשר שדורש שם,)instanceof( לא ניתן לממש מספר מנשקים, לקוחות מוגבלים לממשק של טיפוס האב, גישה למשתנים מקומיים שהם final בלבד. מחלקה אנונימית צריכה להיות קצרה כדי לא לפגוע בקריאות של הקוד

22 22 דוגמאות שימוש Function object (functor) מיון מחרוזות לפי אורך Arrays.sort(stringArray, new Comparator<String>() { public int compare(string s1, String s2) { return s1.length() - s2.length(); ); public Iterator<E> iterator() { return new Iterator<E>() { boolean hasnext() {... E next() {... void remove() {... ; מימוש איטרטור

23 23 המרה ממערך לרשימה static List<Integer> intarrayaslist(final int[] a) { if (a == null) throw new IllegalArgumentException(); return new AbstractList<Integer>() { public Integer get(int i) { גישה למשתנים מקומיים return a[i]; שהוגדרו final public Integer set(int i, Integer val) { int oldval = a[i]; a[i] = val; return oldval; public int size() { return a.length; ;

תוכנה 1. תרגול מספר 11: Static vs. Dynamic Binding מחלקות מקוננות Nested Classes

תוכנה 1. תרגול מספר 11: Static vs. Dynamic Binding מחלקות מקוננות Nested Classes תוכנה 1 תרגול מספר 11: Static vs. Dynamic Binding מחלקות מקוננות Nested Classes class Outer { static class NestedButNotInner {... class Inner {... מחלקות מקוננות NESTED CLASSES 2 מחלקה מקוננת Class) )Nested

More information

תוכנה 1 ומחלקות פנימיות

תוכנה 1 ומחלקות פנימיות תוכנה 1 Design Patterns ומחלקות פנימיות תרגול 11: 1 Design Patterns A general reusable solution to recurring design problems. Not a recipe A higher level language for design Factory, Singleton, Observer

More information

תוכנה 1 סמסטר א' תשע"א

תוכנה 1 סמסטר א' תשעא General Tips on Programming תוכנה 1 סמסטר א' תשע"א תרגול מס' 6 מנשקים, דיאגרמות וביטים * רובי בוים ומתי שמרת Write your code modularly top-down approach Compile + test functionality on the fly Start with

More information

מבוא למדעי המחשב תרגול 8 רשימה משורשרת כללית, Comparator

מבוא למדעי המחשב תרגול 8 רשימה משורשרת כללית, Comparator מבוא למדעי המחשב 2017 תרגול 8 רשימה משורשרת כללית, Comparator בתרגול היום. LinkedList בניית ההכללה מ- LinkIntList תרגול המבנה ושימושיו ממשקים: Comparator Sorted Linked List ל- LinkedList ע"י שימוש ב- Comparator

More information

תוכנה 1 בשפת Java נושאים שונים בהורשה רובי בוים ומתי שמרת בית הספר למדעי המחשב אוניברסיטת תל אביב

תוכנה 1 בשפת Java נושאים שונים בהורשה רובי בוים ומתי שמרת בית הספר למדעי המחשב אוניברסיטת תל אביב תוכנה 1 בשפת Java נושאים שונים בהורשה רובי בוים ומתי שמרת בית הספר למדעי המחשב אוניברסיטת תל אביב Today Static vs. Dynamic binding Equals / hashcode String Immutability (maybe) 2 Static versus run-time

More information

מערכים שעור מס. 4 כל הזכויות שמורות דר ' דרור טובי המרכז האוניברסיטאי אריאל 1

מערכים שעור מס. 4 כל הזכויות שמורות דר ' דרור טובי המרכז האוניברסיטאי אריאל 1 מערכים שעור מס. 4 דרור טובי דר' כל הזכויות שמורות דר ' דרור טובי המרכז האוניברסיטאי אריאל 1 למה מערכים? ברצוננו לאחסן בתוכנית ציוני בחינה כדי לחשב את ממוצע הציונים וסטיית התקן. נניח ש 30 סטודנטים לקחו

More information

הנכות 1 םוכיס לוגרת 13 1

הנכות 1 םוכיס לוגרת 13 1 תוכנה 1 סיכום תרגול 13 1 קצת על מנשקים מנשק יכול להרחיב יותר ממנשק אחד שירותים במנשק הם תמיד מופשטים וציבוריים public interface MyInterface { public abstract int foo1(int i); int foo2(int i); The modifiers

More information

הנכות 1 םוכיס לוגרת 14 1

הנכות 1 םוכיס לוגרת 14 1 תוכנה 1 סיכום תרגול 14 1 קצת על מנשקים מנשק יכול להרחיב יותר ממנשק אחד שירותים במנשק הם תמיד מופשטים וציבוריים public interface MyInterface { public abstract int foo1(int i); int foo2(int i); The modifiers

More information

הנכות 1 םוכיס לוגרת 13 1

הנכות 1 םוכיס לוגרת 13 1 תוכנה 1 סיכום תרגול 13 1 בחינה באופק! הבחינה תכלול את כל הנושאים שכיסינו במהלך הסמסטר: כל ההרצאות כל תרגולים כל תרגילי בית חומר סגור שאלות אמריקאיות 2 קצת על מנשקים מנשק יכול להרחיב שירותים במנשק הם תמיד

More information

הנכות 1 םוכיס לוגרת 13 1

הנכות 1 םוכיס לוגרת 13 1 תוכנה 1 סיכום תרגול 13 1 בחינה באופק! הבחינה תכלול את כל הנושאים שכיסינו במהלך הסמסטר: כל ההרצאות כל תרגולים כל תרגילי בית חומר סגור שאלות אמריקאיות 2 קצת על מנשקים מנשק יכול להרחיב יותר ממנשק אחד שירותים

More information

הקלחמ ה תמרב ת ונ וכ ת (static members ) יליזרב דהוא Java תפשב ם דקת מ תונכת ביבא ל ת תטיסרבינוא

הקלחמ ה תמרב ת ונ וכ ת (static members ) יליזרב דהוא Java תפשב ם דקת מ תונכת ביבא ל ת תטיסרבינוא ת כו נו ת ברמת ה מחלקה (static members) אוהד ברזילי תכנות מ תקד ם בשפת Java אוניברסיטת ת ל אביב static keyword שדות המוגדרים כ static מציינים כי הם מוגדרים ברמת המחלקה ולא ברמת עצם כל העצמים של אותה מחלקה

More information

תוכנה 1 * לא בהכרח בסדר הזה

תוכנה 1 * לא בהכרח בסדר הזה תוכנה 1 תרגול 7: מנשקים, פולימורפיזם ועוד * לא בהכרח בסדר הזה 2 מנשקים מנשקים מנשק )interface( הוא מבנה תחבירי ב- Java המאפשר לחסוך בקוד לקוח. מנשק מכיל כותרות של מתודות המימוש שלהן. )חתימות( ללא קוד אשר

More information

תור שימושים בעולם התוכנה

תור שימושים בעולם התוכנה מבוא למדעי המחשב הרצאה : Queue, Iterator & Iterable תור מבנה נתונים אבסטרקטי תור שימושים בעולם התוכנה השימושים של תורים בעולם התוכנה מזכירים מאוד תורים במציאות: )VoIP( )YouTube( מקלדת שידור סרט באינטרנט

More information

תוכנה 1 מערכים. Array Creation and Initialization. Array Declaration. Array Creation and Initialization. Loop through Arrays

תוכנה 1 מערכים. Array Creation and Initialization. Array Declaration. Array Creation and Initialization. Loop through Arrays מערכים Array: A fixed-length data structure for storing multiple values of the same type תוכנה 1 Example: An array of odd numbers: Indices (start from 0) 0 1 2 3 4 5 6 7 odds: 1 3 5 7 9 11 13 15 odds.length

More information

תוכנה 1 3 תרגול מס' מערכים ומבני בקרה

תוכנה 1 3 תרגול מס' מערכים ומבני בקרה תוכנה 1 3 תרגול מס' מערכים ומבני בקרה מערכים Array: A fixed-length data structure for storing multiple values of the same type Example: An array of odd numbers: Indices (start from 0) 0 1 2 3 4 5 6 7 odds:

More information

תוכנה 1 מערכים. Array Creation and Initialization. Array Declaration. Loop through Arrays. Array Creation and Initialization

תוכנה 1 מערכים. Array Creation and Initialization. Array Declaration. Loop through Arrays. Array Creation and Initialization מערכים תוכנה 1 Array: A fixed-length data structure for storing multiple values of the same type Example from last week: An array of odd numbers: Indices (start from 0) 0 1 2 3 4 5 6 7 תרגול 2: מערכים

More information

תוכנה 1 * לא בהכרח בסדר הזה

תוכנה 1 * לא בהכרח בסדר הזה תוכנה 1 תרגול 7: מנשקים, פולימורפיזם ועוד * לא בהכרח בסדר הזה 2 מנשקים מנשקים - תזכורת מנשק )interface( הוא מבנה תחבירי ב- Java המאפשר לחסוך בקוד לקוח. מנשק מכיל כותרות של מתודות )חתימות(. מימוש דיפולטיבי

More information

מבוא לתכנות ב- JAVA תרגול 7

מבוא לתכנות ב- JAVA תרגול 7 מבוא לתכנות ב- JAVA תרגול 7 רקורסיה - הקדמה הגדרה רקורסיבית: חדר הוא מסודר אם צד שמאל שלו מסודר שלו מסודר. וצד ימין שיטת פתרון רקורסיבית: פתרון מופעים פשוטים יותר של בעיה בכדי לפתור את הבעיה המקורית רקורסיה

More information

Object-Oriented Programming Concepts

Object-Oriented Programming Concepts Object-Oriented Programming Concepts Object-oriented programming מונחה עצמים) (תכנות involves programming using objects An object ) represents (עצם an entity in the real world that can be distinctly identified

More information

תוכנה 1 תרגול 2: מערכים ומבני בקרה

תוכנה 1 תרגול 2: מערכים ומבני בקרה תוכנה 1 תרגול 2: מערכים ומבני בקרה 2 Useful Eclipse Shortcuts Ctrl+1 quick fix for errors, or small refactoring suggestions Ctrl+SPACE code content assist (auto-completion) Auto completion for main create

More information

מבוא למדעי המחשב השפעת השינוי על סטודנט הרצאה 18: פולימורפיזם ומחלקות אבסטרקטיות אם ברצוננו ששכר הלימוד לא יעלה על 2500.

מבוא למדעי המחשב השפעת השינוי על סטודנט הרצאה 18: פולימורפיזם ומחלקות אבסטרקטיות אם ברצוננו ששכר הלימוד לא יעלה על 2500. public class { private static final int COURSE_PRICE = 1000; private String nae; private int id; private int nuofcourses; מבוא למדעי המחשב הרצאה 18 פולימורפיזם ומחלקות אבסטרקטיות תזכורת public (int id,

More information

תכנות מתקדם בשפת C משתנים

תכנות מתקדם בשפת C משתנים תכנות מתקדם בשפת C משתנים 1 משתנים סוגי משתנים בשפת C ההבדלים בין סוגי המשתנים השונים 2 /* This program computes m to the power of n */ /* Assumptions: m is an integer; n is a positive integer */ #include

More information

תזכורת: עץבינארי מבוא למדעי המחשב הרצאה 24: עצי חיפוש בינאריים

תזכורת: עץבינארי מבוא למדעי המחשב הרצאה 24: עצי חיפוש בינאריים מבוא למדעי המחשב הרצאה 2: עצי חיפוש בינאריים תזכורת: עץבינארי בנוסףלרשימהמקושרת ומערך, הצגנומבנהנתונים קונקרטיחדש עץבינארי עץבינארימורכבמ: שורש תת-עץשמאלי תת-עץימני A B C D E F G 2 תזכורת: שורש ותתי-עצים

More information

לתיכנות עם MATLAB Lecture 5: Boolean logic and Boolean expressions

לתיכנות עם MATLAB Lecture 5: Boolean logic and Boolean expressions מבוא לתיכנות עם MATLAB 234127 Lecture 5: Boolean logic and Boolean expressions Written by Prof. Reuven Bar-Yehuda, Technion 2013 Based on slides of Dr. Eran Eden, Weizmann 2008 1 >>g = [89 91 80 98]; >>p

More information

תוכנה 1 תרגול 2: מערכים, מבני בקרה ושגיאות

תוכנה 1 תרגול 2: מערכים, מבני בקרה ושגיאות תוכנה 1 תרגול 2: מערכים, מבני בקרה ושגיאות מערכים Array: A fixed-length data structure for storing multiple values of the same type Example: An array of odd numbers: Indices (start from 0) 0 1 2 3 4 5

More information

תוכנה 1 * לא בהכרח בסדר הזה

תוכנה 1 * לא בהכרח בסדר הזה תוכנה 1 תרגול 7: מנשקים, פולימורפיזם ועוד * לא בהכרח בסדר הזה 2 מנשקים מנשקים מנשק )interface( הוא מבנה תחבירי ב- Java המאפשר לחסוך בקוד לקוח. מנשק מכיל כותרות של מתודות המימוש שלהן. )חתימות( ללא קוד אשר

More information

הנכות 1 תואיגש םע תודדומתהו תואלול,םי : כרעמ 2 לוגרת

הנכות 1 תואיגש םע תודדומתהו תואלול,םי : כרעמ 2 לוגרת תוכנה 1 תרגול 2: מערכים, לולאות והתמודדות עם שגיאות מערכים מערכים Array: A fixed-length data structure for storing multiple values of the same type Example from last week: An array of odd numbers: Indices

More information

לתיכנות עם MATLAB Lecture 5: Boolean logic and Boolean expressions

לתיכנות עם MATLAB Lecture 5: Boolean logic and Boolean expressions מבוא לתיכנות עם MATLAB 23427 Lecture 5: Boolean logic and Boolean expressions Written by Prof. Reuven Bar-Yehuda, Technion 203 Based on slides of Dr. Eran Eden, Weizmann 2008 ביטויים לוגיים דוגמא: תקינות

More information

הנכות 1 תואיגש םע תודדומתהו תואלול,םיכרעמ : לו 2 גרת

הנכות 1 תואיגש םע תודדומתהו תואלול,םיכרעמ : לו 2 גרת תוכנה 1 תרגול 2: מערכים, לולאות והתמודדות עם שגיאות מערכים Array: A fixed-length data structure for storing multiple values of the same type Example from last week: An array of odd numbers: Indices (start

More information

141214 20219031 1 Object-Oriented Programming concepts Object-oriented programming ( תכנות מונחה עצמים ) involves programming using objects An object ) (עצם represents an entity in the real world that

More information

Tutorial 10. Introduction to C++ שימו

Tutorial 10. Introduction to C++ שימו Introduction to ++ שימו תרגול זה אינו התרגול הרישמי של הקורס. הוא מבוסס על חוברת התרגולים אך מכיל שינויים, הסברים נוספים ודוגמאות שונות או נוספות. + + תוכנ ית רא שונה ב הכרו ת עם + + תרגול // First ++

More information

CSE 143 Lecture 26. Advanced collection classes. (ADTs; abstract classes; inner classes; generics; iterators) read 11.1, 9.6, ,

CSE 143 Lecture 26. Advanced collection classes. (ADTs; abstract classes; inner classes; generics; iterators) read 11.1, 9.6, , CSE 143 Lecture 26 Advanced collection classes (ADTs; abstract classes; inner classes; generics; iterators) read 11.1, 9.6, 15.3-15.4, 16.4-16.5 slides created by Marty Stepp, adapted by Alyssa Harding

More information

תוכנה 1 תרגול מספר 13

תוכנה 1 תרגול מספר 13 1 תוכנה 1 תרגול מספר 13 ו- HashCode Equals עוד על טיפוסים מוכללים )Advanced Generics( חריגים )Exceptions( בית הספר למדעי המחשב אוניברסיטת תל אביב 1 2 ו- HASHCODE EQUALS 3 תזכורת: המחלקה Object package

More information

תוכנה 1 תרגול מספר 13

תוכנה 1 תרגול מספר 13 1 2 תוכנה 1 תרגול מספר 13 ו- HashCode Equals עוד על טיפוסים מוכללים )Advanced Generics( ו- HASHCODE EQUALS חריגים )Exceptions( בית הספר למדעי המחשב אוניברסיטת תל אביב 1 3 4 package java.lang; תזכורת: המחלקה

More information

List ADT. Announcements. The List interface. Implementing the List ADT

List ADT. Announcements. The List interface. Implementing the List ADT Announcements Tutoring schedule revised Today s topic: ArrayList implementation Reading: Section 7.2 Break around 11:45am List ADT A list is defined as a finite ordered sequence of data items known as

More information

Overview of Java s Support for Polymorphism

Overview of Java s Support for Polymorphism Overview of Java s Support for Polymorphism Douglas C. Schmidt d.schmidt@vanderbilt.edu www.dre.vanderbilt.edu/~schmidt Professor of Computer Science Institute for Software Integrated Systems Vanderbilt

More information

ממשק משתמש גרפי בעזרת SWT

ממשק משתמש גרפי בעזרת SWT ממשק משתמש גרפי בעזרת SWT מה עושים היום? קריאת Stack Trace של חריגה hashcode ו- equals ממשק משתמש גרפי תוכנה 1 בשפת Java 2 1 Interpreting Stack Trace of an Exception Exception in thread "main" java.lang.outofmemoryerror:

More information

משתנים שעור מס. 2 כל הזכויות שמורות דר ' דרור טובי המרכז האוניברסיטאי אריאל 1

משתנים שעור מס. 2 כל הזכויות שמורות דר ' דרור טובי המרכז האוניברסיטאי אריאל 1 משתנים שעור מס. 2 דרור טובי דר' כל הזכויות שמורות דר ' דרור טובי המרכז האוניברסיטאי אריאל 1 תפקיד המשתנים הצהרה על משתנה השמת ערך במשתנה int a, b, c; a = 1234; b = 99; c = a + b; משתנים מאפשרים לנו לשמור

More information

תוכנה 1 מבני נתונים גנריים

תוכנה 1 מבני נתונים גנריים תוכנה 1 מבני נתונים גנריים תרגול 8 Java Collections Framework Collection: a group of elements Interface Based Design: Java Collections Framework Interfaces Implementations Algorithms 2 Online Resources

More information

Enumerated Types טיפוסי מנייה בית הספר למדעי המחשב אוניברסיטת תל אביב

Enumerated Types טיפוסי מנייה בית הספר למדעי המחשב אוניברסיטת תל אביב Enumerated Types טיפוסי מנייה בית הספר למדעי המחשב אוניברסיטת תל אביב Enumerated Types טיפוסים שכל מופעיהם קבועים וידועים מראש שכיחים מאוד בעולם התוכנה: package cards.domain; public class PlayingCard {

More information

מבוא למדעי המחשב הרצאה 18: פולימורפיזם ומחלקות אבסטרקטיות

מבוא למדעי המחשב הרצאה 18: פולימורפיזם ומחלקות אבסטרקטיות מבוא למדעי המחשב הרצאה 18: פולימורפיזם ומחלקות אבסטרקטיות 1 class Student public class Student { private static final int COURSE_PRICE = 1000; private String name; private int id; private int numofcourses;

More information

Simple Web Service. namespace MyService { public class Service1 : System.Web.Services.WebService {

Simple Web Service. namespace MyService { public class Service1 : System.Web.Services.WebService { Simple Web Service WS פתיחת פרוייקט File New Project ASP.Net web service project - >http://localhost/webservice1 יצירת שירות המחשב חיבור וחילוק 2 מספרים : הטיפוסים הבסיסיים using System; איסוף וניהוף אוספי

More information

מצליחה. 1. int fork-bomb() 2. { 3. fork(); 4. fork() && fork() fork(); 5. fork(); printf("bla\n"); 8. return 0; 9. }

מצליחה. 1. int fork-bomb() 2. { 3. fork(); 4. fork() && fork() fork(); 5. fork(); printf(bla\n); 8. return 0; 9. } שאלה : (4 נקודות) א. ב. ג. (5 נקודות) הגדירו את המונח race-condition במדוייק לא להשמיט פרטים. ספקו דוגמא. (5 נקודות) מהו? Monitor נא לספק הגדרה מלאה. ( נקודות) ( נקודות) ציינו כמה תהליכים יווצרו בקוד הבא

More information

תכנות מונחה עצמים משחקים תשע"ו

תכנות מונחה עצמים משחקים תשעו move semantics 1 תכנות מונחה עצמים ופיתוח משחקים תשע"ו סמנטיקת ההעברה semantics( )Move move semantics 2 מטרה האצה של התוכניות, שיפור בביצועים על ידי חסכון בבנייה והעתקה של אובייקטים זמניים move semantics

More information

תוכנה 1 בשפת Java תרגול מספר 9: הורשה רובי בוים ומתי שמרת בית הספר למדעי המחשב אוניברסיטת תל אביב

תוכנה 1 בשפת Java תרגול מספר 9: הורשה רובי בוים ומתי שמרת בית הספר למדעי המחשב אוניברסיטת תל אביב תרגול מספר 9: הורשה רובי בוים ומתי שמרת בית הספר למדעי המחשב ירושה ממחלקות קיימות ראינו בהרצאה שתי דרכים לשימוש חוזר בקוד של מחלקה קיימת: הכלה + האצלה ירושה המחלקה היורשת יכולה להוסיף פונקציונליות שלא

More information

מבוא לתכנות ב- JAVA מעבדה 2

מבוא לתכנות ב- JAVA מעבדה 2 מבוא לתכנות ב- JAVA מעבדה 2 מה בתרגול טיפוסים פרימיטיביים המרות טיפוסים אופרטורים יחסיים ולוגיים משפט if-else בתרגול הקודם טיפוסים פרימיטביים לייצוג מספרים שלמים וממשיים ואופרטורים לפעולות בין מספרים.1

More information

תוכנה 1 מבני נתונים גנריים

תוכנה 1 מבני נתונים גנריים תוכנה 1 מבני נתונים גנריים תרגול 8 2 Java Collections Framework Collection: a group of elements Interface Based Design: Java Collections Framework Interfaces Implementations Algorithms 3 Online Resources

More information

public static boolean isoutside(int min, int max, int value)

public static boolean isoutside(int min, int max, int value) See the 2 APIs attached at the end of this worksheet. 1. Methods: Javadoc Complete the Javadoc comments for the following two methods from the API: (a) / @param @param @param @return @pre. / public static

More information

שיעור מספר 8: "אמא יש רק אחת" )הורשה I(

שיעור מספר 8: אמא יש רק אחת )הורשה I( שיעור מספר 8: "אמא יש רק אחת" )הורשה I( שחר מעוז בית הספר למדעי המחשב על סדר היום יחסים בין מחלקות ירושה כיחס is-a טיפוס סטטי וטיפוס דינמי המחלקה Object מחלקות מופשטות 2 מלבן צבעוני נרצה לבנות מחלקה המייצגת

More information

ENUMERATED TYPES טיפוסי מנייה שחר מעוז תוכנה 1 בשפת ג'אווה אוניברסיטת תל אביב

ENUMERATED TYPES טיפוסי מנייה שחר מעוז תוכנה 1 בשפת ג'אווה אוניברסיטת תל אביב ENUMERATED TYPES טיפוסי מנייה שחר מעוז אוניברסיטת תל אביב ENUMERATED TYPES package cards.domain; public class PlayingCard { טיפוסים שכל מופעיהם קבועים וידועים מראש שכיחים מאוד בעולם התוכנה: // pseudo enumerated

More information

public class B { private int f = 0; public static void main(string[] args) { B b1 = new B(); B b2 = new B(); Object b3 = b1;

public class B { private int f = 0; public static void main(string[] args) { B b1 = new B(); B b2 = new B(); Object b3 = b1; main /***/ public class B { private int f = 0; public static void main(string[] args) { B b1 = new B(); B b2 = new B(); Object b3 = b1; System.out.println(/***/); @Override public boolean equals(object

More information

Collections and Iterators. Collections

Collections and Iterators. Collections Collections and Iterators Based on the notes from David Fernandez-Baca and Steve Kautz Based on The Java Tutorial (http://docs.oracle.com/javase/tutorial/java/) Bryn Mawr College CS206 Intro to Data Structures

More information

ב ה צ ל ח ה! אוניברסיטת בן גוריון בנגב מספר נבחן : תאריך המבחן: כ"ה תשרי תשע"ח 15/10/17 שמות המורים: ציון סיקסיק מיועד לתלמידי : א'

ב ה צ ל ח ה! אוניברסיטת בן גוריון בנגב מספר נבחן : תאריך המבחן: כה תשרי תשעח 15/10/17 שמות המורים: ציון סיקסיק מיועד לתלמידי : א' אוניברסיטת בן גוריון בנגב מספר נבחן : תאריך המבחן: כ"ה תשרי תשע"ח 15/10/17 שמות המורים: ציון סיקסיק א' ב- C תכנות מבחן ב: 202-1-9011 מס' הקורס : הנדסה מיועד לתלמידי : א' מועד קיץ סמ' שנה תשע"ז 3 שעות משך

More information

Lists. The List ADT. Reading: Textbook Sections

Lists. The List ADT. Reading: Textbook Sections Lists The List ADT Reading: Textbook Sections 3.1 3.5 List ADT A list is a dynamic ordered tuple of homogeneous elements A o, A 1, A 2,, A N-1 where A i is the i-th element of the list The position of

More information

Day 4. COMP1006/1406 Summer M. Jason Hinek Carleton University

Day 4. COMP1006/1406 Summer M. Jason Hinek Carleton University Day 4 COMP1006/1406 Summer 2016 M. Jason Hinek Carleton University today s agenda assignments questions about assignment 2 a quick look back constructors signatures and overloading encapsulation / information

More information

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University CS5000: Foundations of Programming Mingon Kang, PhD Computer Science, Kennesaw State University OOP Three main programming mechanisms that constitute object-oriented programming (OOP) Encapsulation Inheritance

More information

Java Class Design. Eugeny Berkunsky, Computer Science dept., National University of Shipbuilding

Java Class Design. Eugeny Berkunsky, Computer Science dept., National University of Shipbuilding Java Class Design Eugeny Berkunsky, Computer Science dept., National University of Shipbuilding eugeny.berkunsky@gmail.com http://www.berkut.mk.ua Objectives Implement encapsulation Implement inheritance

More information

Algorithms. Intro2CS week 5

Algorithms. Intro2CS week 5 Algorithms Intro2CS week 5 1 Computational problems A computational problem specifies an inputoutput relationship What does the input look like? What should the output be for each input? Example: Input:

More information

שיעור מספר 3: "מחלקות וטיפוסים"

שיעור מספר 3: מחלקות וטיפוסים שיעור מספר 3: "מחלקות וטיפוסים" בית הספר למדעי המחשב על סדר היום מודל הזיכרון של Java Heap and Stack העברת ארגומנטים מנגנוני שפת Java עצמים ושירותי מופע 2 העברת ארגומנטים כאשר מתבצעת קריאה לשרות, ערכי

More information

תוכנה 1. תרגול מס' 3 עבודה עם מחרוזות )Strings( מתודות )Methods( העברת פרמטרים

תוכנה 1. תרגול מס' 3 עבודה עם מחרוזות )Strings( מתודות )Methods( העברת פרמטרים תוכנה 1 תרגול מס' 3 עבודה עם מחרוזות )Strings( מתודות )Methods( העברת פרמטרים שלבי הפיתוח - חזרה קצרה ישנם שני שלבים נפרדים: שלב פיתוח התוכנית בשלב זה אנו משתמשים במהדר )קומפיילר( כדי להמיר קבצי.java )קבצי

More information

<exp> ::= <define> <cexp> <define> ::= ( define <var-decl> <cexp> ) / DefExp(var:VarDecl, val:cexp)

<exp> ::= <define> <cexp> <define> ::= ( define <var-decl> <cexp> ) / DefExp(var:VarDecl, val:cexp) הנחיות כלליות: תאריך הבוחן: 10.5.2018 שם המרצה: מני אדלר,מיכאל אלחדד, ירון גונן מבחן בקורס: עקרונות שפות תכנות מס' קורס: 202-1-2051 מיועד לתלמידי: מדעי המחשב והנדסת תוכנה שנה: ב' סמסטר: ב' משך הבוחן: 2

More information

PIC 20A Collections and Data Structures

PIC 20A Collections and Data Structures PIC 20A Collections and Data Structures Ernest Ryu UCLA Mathematics Last edited: March 14, 2018 Introductory example How do you write a phone book program? Some programmers may yell hash table! and write

More information

1 Shyam sir JAVA Notes

1 Shyam sir JAVA Notes 1 Shyam sir JAVA Notes 1. What is the most important feature of Java? Java is a platform independent language. 2. What do you mean by platform independence? Platform independence means that we can write

More information

Selected Questions from by Nageshwara Rao

Selected Questions from  by Nageshwara Rao Selected Questions from http://way2java.com by Nageshwara Rao Swaminathan J Amrita University swaminathanj@am.amrita.edu November 24, 2016 Swaminathan J (Amrita University) way2java.com (Nageshwara Rao)

More information

- מבחן. - 4 עבודות ב- JAVA. הגשה בזוגות דרך ה- System Submission

- מבחן. - 4 עבודות ב- JAVA. הגשה בזוגות דרך ה- System Submission 1 - מבחן. - 4 עבודות ב- JAVA 60% 40% הגשה בזוגות דרך ה- System Submission 2 UML Class Diagrams Packages Class Path JAR Files חלק ראשון: חלק שני: 3 An abstraction of software features A structure that singles

More information

ITI Introduction to Computing II

ITI Introduction to Computing II ITI 1121. Introduction to Computing II Marcel Turcotte School of Information Technology and Engineering Iterator (part II) Inner class Implementation: fail-fast Version of March 20, 2011 Abstract These

More information

תרגול 6 רקורסיה ותכנות מונחה עצמים

תרגול 6 רקורסיה ותכנות מונחה עצמים מבוא למדעי המחשב 2017 תרגול 6 רקורסיה ותכנות מונחה עצמים מבוא למדעי המחשב 1 ראינו בהרצאה רקורסיה תכנות מונחה עצמים: מחלקה ואובייקט שדות, בנאים ושיטות מימוש מערך דינאמי של ראשוניים בתרגול היום רקורסיה הדפסת

More information

Java: introduction to object-oriented features

Java: introduction to object-oriented features Chair of Software Engineering Carlo A. Furia, Marco Piccioni, Bertrand Meyer Java: introduction to object-oriented features Chair of Software Engineering Carlo A. Furia, Marco Piccioni, Bertrand Meyer

More information

Functors. 01/23/03 Lecture 5 1

Functors. 01/23/03 Lecture 5 1 Functors A functor is an object with no data and a single method. Functors can be passed as parameters. Since these classes are very small, they are usually implemented as a Nested Class wherever they

More information

תרגול מספר 3: מערכים

תרגול מספר 3: מערכים היום בתרגול:.1.2 תרגול מספר 3: מערכים מערך חד-מימדי: מה זה מערך ולמה צריך אותו? איך מגדירים? איך זה נראה בזכרון? דוגמאות לשימוש במערך חד-מימדי השוואה בין משתנה פרימיטיבי למשתנה שאינו פרימיטיבי מערך דו-מימדי:

More information

CMSC132 Summer 2018 Midterm 1

CMSC132 Summer 2018 Midterm 1 CMSC132 Summer 2018 Midterm 1 First Name (PRINT): Last Name (PRINT): Instructions This exam is a closed-book and closed-notes exam. Total point value is 100 points. The exam is a 80 minutes exam. Please

More information

CS-140 Fall 2017 Test 1 Version Practice Practice for Nov. 20, Name:

CS-140 Fall 2017 Test 1 Version Practice Practice for Nov. 20, Name: CS-140 Fall 2017 Test 1 Version Practice Practice for Nov. 20, 2017 Name: 1. (10 points) For the following, Check T if the statement is true, the F if the statement is false. (a) T F : If a child overrides

More information

Fundamentals of Object Oriented Programming

Fundamentals of Object Oriented Programming INDIAN INSTITUTE OF TECHNOLOGY ROORKEE Fundamentals of Object Oriented Programming CSN- 103 Dr. R. Balasubramanian Associate Professor Department of Computer Science and Engineering Indian Institute of

More information

שאלה 1 מהו הפלט של התוכנית הבאה:

שאלה 1 מהו הפלט של התוכנית הבאה: תרגול חזרה שאלה 1 מהו הפלט של התוכנית הבאה: public sttic int wht(int n) { int i; int sum=0; if(n == 0) return 1; for (i=0; i

More information

Nir Adar

Nir Adar שפת Java למתכנתי ++C - חלק שני מסמך זה הורד מהאתר. אין להפיץ מסמך זה במדיה כלשהי, ללא אישור מפורש מאת המחבר. מחבר המסמך איננו אחראי לכל נזק, ישיר או עקיף, שיגרם עקב השימוש במידע המופיע במסמך, וכן לנכונות

More information

Rules and syntax for inheritance. The boring stuff

Rules and syntax for inheritance. The boring stuff Rules and syntax for inheritance The boring stuff The compiler adds a call to super() Unless you explicitly call the constructor of the superclass, using super(), the compiler will add such a call for

More information

Implements vs. Extends When Defining a Class

Implements vs. Extends When Defining a Class Implements vs. Extends When Defining a Class implements: Keyword followed by the name of an INTERFACE Interfaces only have method PROTOTYPES You CANNOT create on object of an interface type extends: Keyword

More information

תוכנה 1 מבני נתונים גנריים

תוכנה 1 מבני נתונים גנריים תוכנה 1 מבני נתונים גנריים תרגול 8 2 Java Collections Framework Collection: a group of elements Interface Based Design: Java Collections Framework Interfaces Implementations Algorithms 3 Online Resources

More information

Java פעולות עוברות בירושה סביבת יסודות מדעי המחשב נספח הורשה

Java פעולות עוברות בירושה סביבת יסודות מדעי המחשב נספח הורשה 1 נספח הורשה פעולות עוברות בירושה.1 הפעולה ToString המחלקה קלף Card נכתוב את המחלקה המגדירה עצם מסוג קלף. תכונות המחלקה: מחרוזת המתארת את צורת הקלף )תלתן, מעוין, לב, עלה( מספר שלם בתחום 13-1 )כולל( המהווה

More information

CMSC132 Summer 2018 Midterm 1. Solution

CMSC132 Summer 2018 Midterm 1. Solution CMSC132 Summer 2018 Midterm 1 Solution First Name (PRINT): Last Name (PRINT): Instructions This exam is a closed-book and closed-notes exam. Total point value is 100 points. The exam is a 80 minutes exam.

More information

PASS4TEST IT 인증시험덤프전문사이트

PASS4TEST IT 인증시험덤프전문사이트 PASS4TEST IT 인증시험덤프전문사이트 http://www.pass4test.net 일년동안무료업데이트 Exam : 1z0-809 Title : Java SE 8 Programmer II Vendor : Oracle Version : DEMO Get Latest & Valid 1z0-809 Exam's Question and Answers 1 from

More information

9. טופס הזמנת מוצרים טופס ההזמנה הוא טופס מורכב. מעורבים בו 4 טבלאות נתונים. קשרי הגומלין בין הטבלאות : הטופס :

9. טופס הזמנת מוצרים טופס ההזמנה הוא טופס מורכב. מעורבים בו 4 טבלאות נתונים. קשרי הגומלין בין הטבלאות : הטופס : 9. טופס הזמנת מוצרים טופס ההזמנה הוא טופס מורכב. מעורבים בו 4 טבלאות נתונים. קשרי הגומלין בין הטבלאות : הטופס : 1 בהרצה : הוספת פריט רשימת פריטים ההכנה לעבודה : 1. להוסיף שתי טבלאות למאגר טבלת orders וטבלת.orderDetail

More information

Lesson 10. Work with Interfaces and Abstract Classes. Copyright all rights reserved

Lesson 10. Work with Interfaces and Abstract Classes. Copyright all rights reserved Lesson 10 Work with Interfaces and Abstract Classes Copyright 1999-2000 all rights reserved Lesson Objectives Upon completion of this lesson you should be able to Create an interface Implement an interface

More information

Overriding המחלקה למדעי המחשב עזאם מרעי אוניברסיטת בן-גוריון

Overriding המחלקה למדעי המחשב עזאם מרעי אוניברסיטת בן-גוריון Overriding עזאם מרעי המחלקה למדעי המחשב אוניברסיטת בן-גוריון 2 Roadmap A method in a child class overrides a method in the parent class if it has the same name and type signature: Parent void method(int,float)

More information

תרשים המחלקות ותרשים העצמים

תרשים המחלקות ותרשים העצמים 1 תרשים המחלקות ותרשים העצמים חלק שלישי: ניתוח ועיצוב מערכות מידע באמצעות שימוש ב- UML ומתודולוגיית ה- Process )UP( Unified E1 3 E2 2 Outline UML Introduction Class Diagram Class Association Self association

More information

Class definition. complete definition. public public class abstract no instance can be created final class cannot be extended

Class definition. complete definition. public public class abstract no instance can be created final class cannot be extended JAVA Classes Class definition complete definition [public] [abstract] [final] class Name [extends Parent] [impelements ListOfInterfaces] {... // class body public public class abstract no instance can

More information

Programming Languages and Techniques (CIS120)

Programming Languages and Techniques (CIS120) Programming Languages and Techniques (CIS120) Lecture 29 April 3, 2014 Overriding, Enums, Iterators public class Ref { private T contents; public void add(t e) { contents = e; Quiz (on paper) public

More information

Framework Fundamentals

Framework Fundamentals Questions Framework Fundamentals 1. Which of the following are value types? (Choose all that apply.) A. Decimal B. String C. System.Drawing.Point D. Integer 2. Which is the correct declaration for a nullable

More information

תרגול 3 מערכים ופונקציות

תרגול 3 מערכים ופונקציות מבוא למדעי המחשב 2017 תרגול 3 מערכים ופונקציות מערכים מאפשרים עבודה עם מקבצים של נתונים פונקציות מאפשרות אבסטרקציה והאחדה של הקוד ראינו בהרצאה מערכים הצהרה, אתחול, גישה לאיברים במערך יצוג בזיכרון ובטבלת

More information

CSCI-142 Exam 1 Review September 25, 2016 Presented by the RIT Computer Science Community

CSCI-142 Exam 1 Review September 25, 2016 Presented by the RIT Computer Science Community CSCI-12 Exam 1 Review September 25, 2016 Presented by the RIT Computer Science Community http://csc.cs.rit.edu 1. Provide a detailed explanation of what the following code does: 1 public boolean checkstring

More information

Asymptotically almost every 2r-regular graph has an internal partition

Asymptotically almost every 2r-regular graph has an internal partition האוניברסיטה העברית בירושלים הפקולטה למתמטיקה ולמדעי הטבע בית הספר למדעי המחשב The Hebrew University of Jerusalem Faculty of Science The Rachel and Selim Benin School of Computer Science and Engineering

More information

CSE 143 Lecture 14. Interfaces; Abstract Data Types (ADTs) reading: 9.5, 11.1; 16.4

CSE 143 Lecture 14. Interfaces; Abstract Data Types (ADTs) reading: 9.5, 11.1; 16.4 CSE 143 Lecture 14 Interfaces; Abstract Data Types (ADTs) reading: 9.5, 11.1; 16.4 slides adapted from Marty Stepp and Hélène Martin http://www.cs.washington.edu/143/ Related classes Consider classes for

More information

Java Fundamentals (II)

Java Fundamentals (II) Chair of Software Engineering Languages in Depth Series: Java Programming Prof. Dr. Bertrand Meyer Java Fundamentals (II) Marco Piccioni static imports Introduced in 5.0 Imported static members of a class

More information

היצביט ומ - ןוכית ת וי נבת

היצביט ומ - ןוכית ת וי נבת תבני ו ת תיכון Patterns) (Design תבנ יו ת תיכון - מו טיבציה בחיי היום יום אנחנו מתארים דברים תוך שימוש בתבניות חוזרות: "מכונית א' היא כמו מכונית ב', אבל יש לה 2 דלתות במקום 4" "אני רוצה ארון כמו זה, אבל

More information

What is Inheritance?

What is Inheritance? Inheritance 1 Agenda What is and Why Inheritance? How to derive a sub-class? Object class Constructor calling chain super keyword Overriding methods (most important) Hiding methods Hiding fields Type casting

More information

לתיכנות עם MATLAB Lecture 5: Boolean logic and Boolean expressions

לתיכנות עם MATLAB Lecture 5: Boolean logic and Boolean expressions מבוא לתיכנות עם MATLAB 234127 Lecture 5: Boolean logic and Boolean expressions Written by Prof. Reuven Bar-Yehuda, Technion 2013 Based on slides of Dr. Eran Eden, Weizmann 2008 1 motivation Proper academic

More information

ספרית התבניות הסטנדרטית (STL) כתיבת אלגוריתמים גנריים מצביעים חכמים. .vector. list iterator נכיר תחילה את האוסף הפשוט ביותר בספריה

ספרית התבניות הסטנדרטית (STL) כתיבת אלגוריתמים גנריים מצביעים חכמים. .vector. list iterator נכיר תחילה את האוסף הפשוט ביותר בספריה ספרית התבניות הסטנדרטית (STL) כתיבת אלגוריתמים גנריים מצביעים חכמים vector list iterator 2 קיימת בכל מימוש של ++C מכילה אוספים (Containers) ואלגוריתמים נכיר תחילה את האוסף הפשוט ביותר בספריה.vector מערך

More information

Example: Count of Points

Example: Count of Points Example: Count of Points 1 class Point { 2... 3 private static int numofpoints = 0; 4 5 Point() { 6 numofpoints++; 7 } 8 9 Point(int x, int y) { 10 this(); // calling the constructor with no input argument;

More information

ITI Introduction to Computing II

ITI Introduction to Computing II ITI 1121. Introduction to Computing II Iterator 1 (part I) Marcel Turcotte School of Electrical Engineering and Computer Science Version of March 26, 2013 Abstract These lecture notes are meant to be looked

More information

Software 1. תרגול 9 Java I/O

Software 1. תרגול 9 Java I/O Software 1 תרגול 9 Java I/O 1 The java.io package The java.io package provides: Classes for reading input Classes for writing output Classes for manipulating files Classes for serializing objects 2 Streams

More information